package com.cat.model.web.action.admin.acnt;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.alonew.core.commons.page.Page;
import com.alonew.db.dao.TxCommonDAO;
import com.cat.model.dao.common.PlmCommDAO;
import com.cat.model.dao.mapper.ModelMapper;
import com.cat.model.web.action.base.AdminAction;
import com.cat.model.web.bean.AccountBean;

public class AccountManagerAction extends AdminAction{
	/**
	 * 
	 */
	private static final long serialVersionUID = 425636316597986569L;
	
	private Long id;
	private String userId;
	private Long accountId;
	private Date createBeginTime;
	private Date createEndTime;
	private BigDecimal minAmount;
	private BigDecimal maxAmount;
		
	@Autowired
	private PlmCommDAO plmCommDAO;
	
	@Autowired
	private TxCommonDAO commonDAO;
	
	@Autowired
	private ModelMapper modelMapper;
	
	/**
	 * list
	 * 
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public String list() {
		Map<String, Object> condition = new HashMap<String, Object>();
		
		if(StringUtils.isNotEmpty(userId)){
			condition.put("userId", userId);
		}
		
		Page page = this.fetchPageParams();
		page.setNumPerPage(20);
		
		Long totalCount = plmCommDAO.searchSize("manager.searchAccountSize", condition);
		page.setTotalCount(totalCount);
		int start = (page.getPageNum() -1) * page.getNumPerPage();
		if(start < 0){
			start = 0;
		}
		
		List<AccountBean> list = (List<AccountBean>)plmCommDAO.search("manager.searchAccount", condition, start, page.getNumPerPage());
		
		request.setAttribute("list", list);
		request.setAttribute("size", totalCount);
		return "list";
	}
	
	@SuppressWarnings("unchecked")
	public String detail() {
		Map<String, Object> condition = new HashMap<String, Object>();
		
		if(accountId != null){
			condition.put("accountId", accountId);
		}
		
		if(createBeginTime != null){
			condition.put("createBeginTime", createBeginTime);
		}
		
		if(createEndTime != null){
			condition.put("createEndTime", createEndTime);
		}
		
		if(minAmount != null){
			condition.put("minAmount", minAmount);
		}
		
		if(maxAmount != null){
			condition.put("maxAmount", maxAmount);
		}
		
		Page page = this.fetchPageParams();
		page.setNumPerPage(20);
		
		Long totalCount = plmCommDAO.searchSize("manager.searchAccountDSize", condition);
		page.setTotalCount(totalCount);
		int start = (page.getPageNum() -1) * page.getNumPerPage();
		if(start < 0){
			start = 0;
		}
		
		List<AccountBean> list = (List<AccountBean>)plmCommDAO.search("manager.searchAccountD", condition, start, page.getNumPerPage());
		
		request.setAttribute("list", list);
		request.setAttribute("size", totalCount);
		return "detail";
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public Long getAccountId() {
		return accountId;
	}

	public void setAccountId(Long accountId) {
		this.accountId = accountId;
	}

	public Date getCreateBeginTime() {
		return createBeginTime;
	}

	public void setCreateBeginTime(Date createBeginTime) {
		this.createBeginTime = createBeginTime;
	}

	public Date getCreateEndTime() {
		return createEndTime;
	}

	public void setCreateEndTime(Date createEndTime) {
		this.createEndTime = createEndTime;
	}

	public BigDecimal getMinAmount() {
		return minAmount;
	}

	public void setMinAmount(BigDecimal minAmount) {
		this.minAmount = minAmount;
	}

	public BigDecimal getMaxAmount() {
		return maxAmount;
	}

	public void setMaxAmount(BigDecimal maxAmount) {
		this.maxAmount = maxAmount;
	}


}
